home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / firefox / firefox < prev    next >
Encoding:
Text File  |  2007-04-03  |  8.4 KB  |  306 lines

  1. #!/bin/bash
  2. #
  3. # The contents of this file are subject to the Netscape Public
  4. # License Version 1.1 (the "License"); you may not use this file
  5. # except in compliance with the License. You may obtain a copy of
  6. # the License at http://www.mozilla.org/NPL/
  7. #
  8. # Software distributed under the License is distributed on an "AS
  9. # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. # implied. See the License for the specific language governing
  11. # rights and limitations under the License.
  12. #
  13. # The Original Code is mozilla.org code.
  14. #
  15. # The Initial Developer of the Original Code is Netscape
  16. # Communications Corporation.  Portions created by Netscape are
  17. # Copyright (C) 1998 Netscape Communications Corporation. All
  18. # Rights Reserved.
  19. #
  20. # Contributor(s): 
  21. #
  22.  
  23. ##
  24. ## For silly people running firefox through sudo
  25. ##
  26. if [ "${SUDO_USER}" ] && [ "${SUDO_USER}" != "${USER}" ]; then
  27.     SUDO_HOME=`getent passwd ${SUDO_USER} | cut -f6 -d:`
  28.     if [ "${SUDO_HOME}" = "${HOME}" ]; then
  29.         echo "You should really not run firefox through sudo WITHOUT the -H option." >&2
  30.         echo "Anyway, I'll do as if you did use the -H option." >&2
  31.         HOME=`getent passwd ${USER} | cut -f6 -d:`
  32.         if [ -z "${HOME}" ]; then
  33.             echo "Could not find the correct home directory. Please use the -H option of sudo." >&2
  34.         fi
  35.     fi
  36. fi
  37.  
  38. ##
  39. ## Variables
  40. ##
  41. MOZ_DIST_BIN="/usr/lib/firefox"
  42. MOZ_PROGRAM="${MOZ_DIST_BIN}/firefox-bin"
  43.  
  44. ##
  45. ## Load system and user properties
  46. ##
  47.  
  48. RUNTIME_FIREFOX_DSP="${FIREFOX_DSP}"
  49.  
  50. if [ -f /etc/firefox/firefoxrc ]; then
  51.     . /etc/firefox/firefoxrc
  52. fi
  53.  
  54. if [ -f "${HOME}/.mozilla/firefox/rc" ]; then
  55.     . "${HOME}/.mozilla/firefox/rc"
  56. elif [ -f "${HOME}/.mozilla-firefoxrc" ]; then
  57.     . "${HOME}/.mozilla-firefoxrc"
  58.     echo "Warning: a .mozilla-firefoxrc file has been found in your home directory" >&2
  59.     echo "While it is still supported, it is recommended to move it to" >&2
  60.     echo "\${HOME}/.mozilla/firefox/rc" >&2
  61. fi
  62.  
  63. if [ "x${MOZ_DISABLE_PANGO}" = x ]; then
  64.     if egrep '^(bn|gu|hi|kn|ml|mr|ne|pa|si|ta|te)_' \
  65.     /var/lib/locales/supported.d/*[^~] >/dev/null 2>&1; then
  66.     MOZ_DISABLE_PANGO=0
  67.     else
  68.     MOZ_DISABLE_PANGO=1
  69.     fi
  70.     export MOZ_DISABLE_PANGO
  71. fi
  72. if [ "x${MOZ_DISABLE_PANGO}" = x0 ]; then
  73.     unset MOZ_DISABLE_PANGO
  74. fi
  75.  
  76. if [ "${RUNTIME_FIREFOX_DSP}" ]; then
  77.     FIREFOX_DSP="${RUNTIME_FIREFOX_DSP}"
  78. fi
  79.  
  80. if [ -z "${FIREFOX_DSP}" ]; then
  81.     #FIREFOX_DSP="auto"
  82.     FIREFOX_DSP="none"
  83.     # esddsp is dreadful, see https://launchpad.net/malone/bugs/29760
  84. fi
  85.  
  86. ##
  87. ## find /dev/dsp handler
  88. ##
  89.  
  90. if [ "${FIREFOX_DSP}" = "auto" ]; then
  91.     FIREFOX_DSP=
  92.     if [ -n "${AUDIOSERVER}" ]; then
  93.         # do not prevent using other wrappers if $AUDIOSERVER was set up
  94.         # unintentionally or audiooss is not available
  95.         if type audiooss >/dev/null 2>&1; then
  96.             FIREFOX_DSP=audiooss
  97.         fi
  98.     fi
  99.     if pgrep -u `id -u` esd >/dev/null 2>&1; then 
  100.         FIREFOX_DSP=esddsp 
  101.     elif pgrep -u `id -u` arts >/dev/null 2>&1; then 
  102.         FIREFOX_DSP=artsdsp 
  103.     elif [ -x /usr/bin/aoss -a -d /proc/asound ] ; then
  104.         FIREFOX_DSP=aoss
  105.     fi
  106. elif [ "${FIREFOX_DSP}" = "none" ]; then
  107.     FIREFOX_DSP=
  108. fi
  109.  
  110. ##
  111. ## Set LD_LIBRARY_PATH
  112. ##
  113. EXTENT_LD_LIB_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:/usr/lib/mozilla-firefox/plugins
  114. if [ "${LD_LIBRARY_PATH}" ]; then
  115.     LD_LIBRARY_PATH=${EXTENT_LD_LIB_PATH}:${LD_LIBRARY_PATH}
  116. else
  117.     LD_LIBRARY_PATH=${EXTENT_LD_LIB_PATH}
  118. fi
  119.  
  120. LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:
  121. LD_LIBRARY_PATH=${LD_LIBRARY_PATH/:\/usr\/lib\/mozilla-thunderbird:/:}
  122. LD_LIBRARY_PATH=${LD_LIBRARY_PATH%:}
  123.  
  124. export LD_LIBRARY_PATH
  125.  
  126. MOZ_PLUGIN_PATH=/usr/lib/mozilla-firefox/plugins${MOZ_PLUGIN_PATH+":$MOZ_PLUGIN_PATH"}
  127. export MOZ_PLUGIN_PATH
  128.  
  129. # Set XPSERVERLIST if not set yet for XPrint support, or complain.
  130.  
  131. #if [ -z "${XPSERVERLIST}" ]; then
  132. #    if [ -x /etc/init.d/xprint ]; then
  133. #        XPSERVERLIST=`/etc/init.d/xprint get_xpserverlist`
  134. #        export XPSERVERLIST
  135. #    else
  136. #        echo -e "Warning: \${XPSERVERLIST} not set and /etc/init.d/xprint not found;\nprinting will not work.\nPlease install the xprt-xprintorg package" >&2
  137. #    fi  
  138. #fi
  139.  
  140. verbose () {
  141.     if [ "${VERBOSE}" ]; then
  142.         echo $@
  143.     fi
  144. }
  145.  
  146. echo_vars () {
  147.     if [ "${VERBOSE}" ]; then
  148.       for var in "$@"; do
  149.           echo "$var=`eval echo \\${$var}`"
  150.       done
  151.     fi
  152. }
  153.     
  154. # exec wrapper for verbosity
  155. exec_verbose () {
  156.     verbose Running: $@
  157.     exec "$@"
  158. }
  159.  
  160. # exec wrapper for verbosity
  161. run_verbose () {
  162.     verbose Running: $@
  163.     "$@"
  164. }
  165.  
  166. # OK, here's where all the real work gets done
  167.  
  168. # parse command line
  169. APPLICATION_ID=firefox
  170. VERBOSE=
  171. DEBUG=0
  172. DEBUGGER=
  173. first=1
  174. opt=
  175. for arg in "$@"; do
  176.     if [ ${first} -eq 1 ]; then
  177.         set dummy
  178.         first=0
  179.     fi
  180.  
  181.     case "${arg}" in
  182.         -a | --display | -contentLocale | -UILocale | -remote | --debugger | -height | -width | -chrome | -P | -CreateProfile)
  183.             prev=${arg}
  184.             continue
  185.         ;;
  186.     esac
  187.     
  188.     if [ "${prev}" ]; then
  189.         case "${prev}" in
  190.             -a)
  191.                 APPLICATION_ID="${arg}"
  192.                 ;;
  193.             -P|-CreateProfile)
  194.                 case "${arg}" in
  195.                 default)    APPLICATION_ID=firefox ;;
  196.                 *)          APPLICATION_ID=firefox--"${arg}" ;;
  197.                 esac
  198.                 MOZ_NO_REMOTE=1
  199.                 export MOZ_NO_REMOTE
  200.                 set "$@" "${prev}" "${arg}"
  201.                 ;;
  202.             --display)
  203.                 CMDLINE_DISPLAY="${arg}"
  204.                 set "$@" --display "${arg}"
  205.                 ;;
  206.             -remote)
  207.                 set "$@" -remote "${arg}"
  208.                 ;;
  209.             --debugger)
  210.                 DEBUGGER="${arg}"
  211.                 DEBUG=1
  212.                 ;;
  213.             *)
  214.                 set "$@" "${prev}" "${arg}"
  215.                 ;;
  216.         esac
  217.         prev=
  218.     elif [ "${arg}" ]; then
  219.         case "$arg" in
  220.             --verbose | -V)
  221.                 VERBOSE=1
  222.                 ;;
  223.             --display=*)
  224.                 CMDLINE_DISPLAY=`echo ${arg} | sed 's/^--display=//'`
  225.                 set "$@" "${arg}"
  226.                 ;;
  227.             -g | -debug)
  228.                 DEBUG=1
  229.                 ;;
  230.             -no-remote)
  231.                 MOZ_NO_REMOTE=1
  232.                 export MOZ_NO_REMOTE
  233.                 ;;
  234.             -ProfileManager)
  235.                 MOZ_NO_REMOTE=1
  236.                 export MOZ_NO_REMOTE
  237.                 APPLICATION_ID="unique--`uname -n`--$$"
  238.                 set "$@" "${arg}"
  239.                 ;;
  240.             -*)
  241.                 set "$@" "${arg}"
  242.                 ;;
  243.             *)
  244.                 if [ -z "${opt}" ]; then
  245.                     opt="${arg}"
  246.                     # check to make sure that the url contains at least a :/ in it.
  247.                     echo ${opt} | grep -e ':/' 2>/dev/null > /dev/null
  248.                     RETURN_VAL=$?
  249.                     if [ "${RETURN_VAL}" -eq 1 ]; then
  250.                     # if it doesn't begin with a '/' and it exists when the pwd is
  251.                     # prepended to it then append the full path
  252.                         echo ${opt} | grep -e '^/' 2>/dev/null > /dev/null
  253.                         if [ "$?" -ne "0" ] && [ -e "`pwd`/${opt}" ]; then
  254.                             opt="`pwd`/${opt}"
  255.                         fi
  256.                         # Make it percent-encoded and prepend file:// if it is a valid file
  257.                         if [ -e "${opt}" ]; then
  258.                           opt="file://$( echo -n "${opt}" | perl -pe "s/([^a-zA-Z0-9-._~\!\\\$&'()*+,=:@\/])/'%'.unpack('H2',\$1)/ge" )"
  259.                         fi
  260.                     fi
  261.                     set "$@" "${opt}"
  262.                 else
  263.                     set "$@" "${arg}"
  264.                 fi
  265.                 ;;
  266.         esac
  267.     fi
  268. done
  269.  
  270. set "$@" "-a" "${APPLICATION_ID}"
  271.  
  272. if [ $# -ne 0 ]; then
  273.     shift
  274. fi
  275. OPTIONS="$@"
  276.  
  277. if [ ${DEBUG} -eq 1 ]; then
  278.     if [ "${DEBUGGER}" = "" ]; then
  279.         DEBUGGER=gdb
  280.     fi
  281.     TMPFILE=`mktemp -t firefox_argsXXXXXX`
  282.     echo set args "$@" > ${TMPFILE}
  283.     case "${DEBUGGER}" in
  284.         gdb)
  285.             run_verbose gdb "${MOZ_PROGRAM}" -x ${TMPFILE}
  286.             ;;
  287.         ddd)
  288.             run_verbose ddd --debugger "gdb -x ${TMPFILE}" "${MOZ_PROGRAM}"
  289.             ;;
  290.         *)
  291.             run_verbose ${DEBUGGER} "${MOZ_PROGRAM}" "$@"
  292.             ;;
  293.     esac
  294.     rm ${TMPFILE}
  295.     exit
  296. fi
  297.  
  298. echo_vars FIREFOX_DSP APPLICATION_ID CMDLINE_DISPLAY DISPLAY \
  299.           OPTIONS DEBUG DEBUGGER MOZ_DISABLE_PANGO MOZ_NO_REMOTE
  300.  
  301. if type "${FIREFOX_DSP}" > /dev/null 2>&1; then
  302.     MOZ_PROGRAM="${FIREFOX_DSP} ${MOZ_PROGRAM}"
  303. fi
  304.  
  305. exec_verbose ${MOZ_PROGRAM} "$@"
  306.